package com.shortvedio.content.service.imp;

import com.shortvedio.base.mapper.FavoritesMapper;
import com.shortvedio.base.model.Result;
import com.shortvedio.base.model.po.Favorites;
import com.shortvedio.content.service.FavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FavoritesServiceImpl implements FavoritesService {

    @Autowired
    private FavoritesMapper favoritesMapper;


    @Override
    public Result addFavorites(Favorites favorites) {
        int insert = favoritesMapper.insert(favorites);
        if (insert<=0){
            return Result.error("添加失败");
        }
        return Result.success("添加成功");
    }

    @Override
    public Result deleteFavorites(Long favoritesId, Long userId) {
        Favorites favorites = favoritesMapper.selectById(favoritesId);
        if (!favorites.getUserId().equals(userId)){
            return Result.error("没有权限删除");
        }
        int delete = favoritesMapper.deleteById(favoritesId);
        if (delete<=0){
            return Result.error("删除失败");
        }
        return Result.success("删除成功");
    }
}
